<?php 
	$fullName = $userLog = $pass = $confirm = $email = $userType = $active = $filename="";
	$control ="insert";
	$btn = "Save";
	if(isset($_REQUEST['control'])){
		$fieldimage = "";
		$fullName=escapeValue($_POST['txtfullName']);
		$userLog=escapeValue($_POST['txtuserLog']);
		$pass=$_POST['txtpass'];
		$confirm=$_POST['txtconfirm'];
		if($pass!="" AND $confirm!=""){
			$pass=md5($pass);
			$confirm=md5($confirm);
		}
		$email=escapeValue($_POST['txtemail']);
		$userType=$_POST['cbouserType'];
		$active=$_POST['cboactive'];
		$filename = escapeValue($_FILES["uploadfile"]["name"]);
		$oldfilename=$_POST['oldfilename'];
		if($pass!=$confirm){
			errorMessage("Password is not match...!");
		}else{
			include("user_verify.php");
		}
	}
	// Select customer info
	if(isset($_GET['user_id'])){
		$querySelectProduct = "SELECT * FROM tbl_user WHERE user_id= $_GET[user_id]";
		$result = mysql_query($querySelectProduct);
		$row = mysql_fetch_array($result);
			$user_id=$_GET['user_id'];
			$fullName=$row['full_name'];
			$userLog = $row['user_name'];
			$confirm = $row['password'];
			$email = $row['email'];
			$userType = $row['type'];
			$active = $row['active'];
			$filename = $row['photo'];
			
			$control = "update&user_id=".$_GET['user_id'];		
			$btn = "Update";	
	}
?>
<table class="bordered" width="770">
        <thead>
            <tr>
                <th>Please insert your user information:<br /><span class="red">* require feild</span></th>
            </tr>
        </thead>
        <tr>
    	<?php 
			if(@$errors!=""){
				echo " <td ><span class='red'>". @$errors."</span></td>";
			}else{
				if(isset($_REQUEST['msgStatus']))
					echo " <td ><span class='red'>". $_REQUEST['msgStatus']."</span></td>";
			 }
			?>
    </tr>
	</table>
<form class="form" action="index.php?page=user_list&action=user_new&control=<?php echo $control;?>" method="post" id="form1" name="form1" enctype="multipart/form-data" >
	
    <table class="bordered" width="770">
		<tr>
			<td>
            	<label><span class="red">*</span> Full Name:</label>
            </td> 
            <td><input type="text" class="input req-min" minlength="1" name="txtfullName" value="<?php echo $fullName ?>" /></td>
		</tr>
        <tr>
        	<td>
            	<label><span class="red">*</span> User Log:</label> 
            </td>
            <td><input type="text" class="input req-min" minlength="1" name="txtuserLog" value="<?php echo $userLog ?>" /></td>
        </tr>
        <?php
			if(@$user_id<>""){
		?>
        <tr>
			<td>
            	<label><span class="red">*</span>Password:</label>
            </td>
            <td><input type="password"  name="txtpass" value="" /></td>
		</tr>
        <tr>
			<td>
            	<label><span class="red">*</span>Confirm:</label>
            </td>
            <td><input type="password" name="txtconfirm" value="" /></td>
		</tr>
        <?php
			}else{
		?>
        <tr>
			<td>
            	<label><span class="red">*</span>Password:</label>
            </td>
            <td><input type="password" class="input req-min" minlength="1" name="txtpass" value="<?php echo $pass ?>" /></td>
		</tr>
        <tr>
			<td>
            	<label><span class="red">*</span>Confirm:</label>
            </td>
            <td><input type="password" class="input req-min" minlength="1" name="txtconfirm" value="<?php echo $confirm ?>" /></td>
		</tr>
		 <?php
			}
        ?>
        <tr>
        	 <td >
            	<label><span class="red">*</span>Email:</label>
            </td>
            <td><input type="text" id="txtPending" class="input req-email" maxlength="50" name="txtemail" value="<?php echo $email ?>" /></td>
        </tr>
        <tr>
        	<td>
            	<label>User Type:</label>
           	</td>
            <td>
            		<select name="cbouserType">
                        <?php
							if($userType=="seller")
							{
								echo "<option value=".$userType." selected='selected'>Seller</option>";
                                echo "<option value='admin'>Admin</option>";
							}
							elseif($userType=="admin")
							{
								echo "<option value='seller'>Seller</option>";
                                echo "<option value=".$userType." selected='selected'>Admin</option>";
							}else{
								echo "<option value='seller' selected='selected'>Seller</option>";
                                echo "<option value='admin'>Admin</option>";
							}
                         ?>
                    </select>
            </td>
		</tr>
        <tr>
        	<td>
            	<label>Active:</label>
           	</td>
            <td>
            		<select name="cboactive">
                        <?php
							if($active=="1")
							{
								echo "<option value=".$active." selected='selected'>Active</option>";
                                echo "<option value='0'>Deactive</option>";
							}
							elseif($active=="0")
							{
								echo "<option value='1'>Active</option>";
                                echo "<option value=".$active." selected='selected'>Deactive</option>";
							}else{
								echo "<option value='1' selected='selected'>Active</option>";
                                echo "<option value='0'>Deactive</option>";
							}
                         ?>
                    </select>
            </td>
		</tr>
        <tr>
        	<td>Upload Your Photo: </td>
            <td>
            	<input type="file" name="uploadfile"  />
                <input type="hidden" name="oldfilename" value="<?php echo $filename;?>" />
                <img src="users/<?php echo $filename;?>" width="80" height="100" />
            </td>
        </tr>
		<tr>
        	<td></td>
			<td ><input type="submit" class="btnSubmit" name="Submit" id="Submit" value="<?php echo $btn ?>" />&nbsp; 
            <input type="button" class="btnSubmit" name="btnSubmit" value="Cancel" onclick="redirect('index.php?page=user_list&action=user_list')" /></td>
		</tr>
	</table>
</form>